#pragma once

enum Event
{
    ReadEvent = 1,
    WriteEvent = 2
};

// 定义函数指针 处理函数
typedef int (*HandelFunc)(void *arg);

// vector<Channel*> channelMap; fd->Channel

class Channel
{
public:
    Channel(int fd, int events, HandelFunc readCallBack, HandelFunc writeCallBack, void *arg)
        : _fd(fd),
          _events(events),
          _readCallBack(readCallBack),
          _writeCallBack(writeCallBack),
          _arg(arg)
    {
    }
    ~Channel()
    {
        if (_fd > 0)
            close(_fd);
    }
    void EnableWriteEvent(bool flag)
    {
        if (flag)
            _events |= WriteEvent;
        else
            _events &= ~WriteEvent;
    }
    bool IsWriteEventEnable()
    {
        return _events & WriteEvent;
    }

public:
    int _fd;                   // 文件描述符
    int _events;               // 事件
    HandelFunc _readCallBack;  // 读回调
    HandelFunc _writeCallBack; // 写回调
    void *_arg;                // 回调参数
};